package com.cdtye.itps.cms.controller.dept;

import com.cdtye.common.webcore.model.po.TreePo;
import com.cdtye.common.webcore.web.AjaxJson;
import com.cdtye.itps.cms.dao.dept.vo.SysDeptVo;
import com.cdtye.itps.cms.service.dept.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 部门 前端控制器
 * @author Jchen
 * @date 2021-07-08
 */
@Api(tags="部门接口")
@RestController
@RequestMapping("/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService modelService;

    @ApiOperation("按条件获取所有单位")
    @GetMapping("/findAllUnitDeptList")
    public AjaxJson<Map<String,Object>> findAllUnitDeptList(){
        List<Map<String,Object>> mapList = modelService.getAllUnitDeptList();
        return AjaxJson.success(mapList);
    }

    @ApiOperation("获取当前登入人可以管理的部门所属单位列表（段，分公司等二级直属单位）")
    @GetMapping("/findManageUnitDeptList")
    public AjaxJson findManageUnitDeptList(SysDeptVo vo){
        List<Map<String,Object>> mapList = modelService.getUnitDeptListByAuth(vo);
        return AjaxJson.success(mapList);
    }

    @ApiOperation("获取当前登入人可以管理的部门树")
    @GetMapping("/findManageDeptTree")
    public AjaxJson<TreePo> getManageDeptTree(SysDeptVo vo){
        List<TreePo> treePoList = modelService.getManageDeptTree(vo.getDeptCode(),vo.getIsManageDept());
        return AjaxJson.success(treePoList);
    }

    @ApiOperation("获取当前用户所管理的接触网工区")
    @GetMapping("/findJcwWorkAreaListByAuth")
    public AjaxJson getJcwWorkAreaListByAuth(String railType){
        List<Map<String, Object>> treePoList = modelService.getJcwWorkAreaListByAuth(railType);
        return AjaxJson.success(treePoList);
    }

    @ApiOperation("根据条件获取部门列表")
    @GetMapping("/getList")
    public AjaxJson getList(SysDeptVo vo){
        return AjaxJson.success(modelService.getList(vo));
    }
}
